package com.hxd.otc.widget;

import android.annotation.SuppressLint;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import android.widget.Toast;

import com.hxd.otc.utils.ResourceUtil;
import com.hxd.otc.utils.UIUtils;

/**
 * 项  目 :  OrderSupervisor
 * 包  名 :  com.example.administrator.blocksbankclient.widget
 * 类  名 :  BlocksToast
 * 作  者 :  胡庆岭
 * 时  间 :  2018/5/31 11:41
 * 描  述 :  ${自定义吐司}
 */
public class BlocksToast {
    private static BlocksToast mOrderToast;
    private Toast mToast;

    private BlocksToast() {
    }

    public static BlocksToast get() {
        synchronized (BlocksToast.class) {
            if (mOrderToast == null) {
                synchronized (BlocksToast.class) {
                    mOrderToast = new BlocksToast();
                }
            }
        }
        return mOrderToast;
    }


    @SuppressLint("ShowToast")
    public void showToast(String text) {
        if (TextUtils.isEmpty(text)) return;
        if (mToast == null) {
            mToast = Toast.makeText(UIUtils.getContext(), text, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(text);
        }
        mToast.show();
    }
    @SuppressLint("ShowToast")
    public void showToastLone(String text) {
        if (TextUtils.isEmpty(text)) return;
        if (mToast == null) {
            mToast = Toast.makeText(UIUtils.getContext(), text, Toast.LENGTH_LONG);
        } else {
            mToast.setText(text);
        }
        mToast.show();
    }

    @SuppressLint("ShowToast")
    public void showToast(@StringRes int resId) {
        showToast(ResourceUtil.getString(resId));
    }

    public void showToast(@StringRes int resId, Object... formatArgs) {
        showToast(ResourceUtil.getString(resId, formatArgs));
    }
}
